﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="IndustryManage.aspx.cs" Inherits="admin_IndustryType_IndustryManage" %>

<%@ Register Src="../../Control/PageNo.ascx" TagName="PageNo" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>行业分类管理</title>
    <link rel="stylesheet" href="../skin/style.css" type="text/css" />

    <script type="text/javascript" src="../../js/jquery.js"></script>
    
    <script type="text/javascript">
    var xmlhttp;
    function ajaxHandle(obj,param){
        var pro="";
        if(param=="0"){
            pro="ThisID="+obj;
        }else if(param=="1"){
           pro="FirstID="+obj.value;
        }else if(param=="2"){
            pro="SecondID="+obj.value;
        }else{
            pro = "MoveToID="+document.getElementById("ddlThird").value;
            if(document.getElementById("ddlThird").value=="-1"||document.getElementById("ddlThird").value==""){
                pro="MoveToID="+document.getElementById("ddlSecond").value;
                if(document.getElementById("ddlSecond").value=="-1"||document.getElementById("ddlSecond").value==""){
                    pro="MoveToID="+document.getElementById("ddlFirst").value;
                }
            }
        }
         xmlHttp = false;
        if (window.XMLHttpRequest){     
            xmlhttp = new XMLHttpRequest();  //　非IE　浏览器
        }else if(window.ActiveXObject){      
            try { //IE
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");//较新版本的IE
            }catch(e){
                try{
                    xmlhttp = new ActiveXOBject("Microsoft.XMLHTTP");//旧版本IE
                }catch(e){}                    
            }
        }else{
                window.alert("不能创建　XMLHttpRequest对象，无法应用Ajax");
                return false;
        };
    
        xmlhttp.onreadystatechange= function(){
            if(xmlhttp.readyState==4){
                if(xmlhttp.status==200) {
                    if(param=="0"){
                        FillDataC(xmlhttp.responseText);
                    }else if(param=="1"){
                        FillData(xmlhttp.responseText,0);
                    }else if(param=="2"){
                        FillData(xmlhttp.responseText,1);
                    }else{
                        LDataI(xmlhttp.responseText);
                    }
                }
                xmlhttp.close();
            }
        };
        xmlhttp.open("GET","IndustryManage.aspx?"+pro,true);
        xmlhttp.send(null);
    }
    function FillData(strName,str){
        var strID="";
        if(str!=1){
            document.getElementById("ddlThird").length=0;
            document.getElementById("divThird").style.display="none";
            document.getElementById("divSecond").style.display="inline";
            strID="ddlSecond";
        }else{
            document.getElementById("divThird").style.display="inline";
            strID="ddlThird"
        }
        
        document.getElementById(strID).length=0;
        document.getElementById(strID).options[0]=new Option("--请选择--","-1");  //.add(new Option("--请选择--","-1")); 
        var ArrayName=strName.substring(0,strName.indexOf("<!"));
        if(ArrayName.length>0) {
             var arrData=new Array();
             arrData= ArrayName.split(",");
             if(arrData.length==1)
                return;
             for(i=0;i<arrData.length;i++) {
                     if(i%2==0)
                        document.getElementById(strID).options[i/2+1]=new Option(arrData[i],arrData[i+1]);
                     else
                         continue;
             }
        }
    }
    </script>
  


    <style type="text/css">
        div.change_background{
        position:absolute;
        padding-top:10px;
        border:1px solid #30789C;
        text-align:Left;
        padding:0;
        width:300px;
        background-color:#F0F7FD;
        filter:alpha(opacity=100);
        }
    </style>

    <script type="text/javascript">
    function beginDrag(elementToDrag,event){
        var oDiv=document.getElementsByTagName("div");
        for(var oD=0;oD<oDiv.length;oD++){
            oDiv[oD].style.zIndex=-1;
        }
        elementToDrag.style.zIndex=1000;
        var x=parseInt(elementToDrag.style.left);
        var y=parseInt(elementToDrag.style.top);
        var deltaX=event.clientX-x;   //获得鼠标点击距离层的左边缘的宽度 
        var deltaY=event.clientY-y;   //获得鼠标点击距离层的上边缘的高度
        var drag=true;
        elementToDrag.setCapture();
        elementToDrag.onmouseup=function(){
            drag=false;
            elementToDrag.releaseCapture();
        }
        elementToDrag.onmousemove=function(){
            if(drag){
                this.style.left=(event.clientX-deltaX)+"px";
                this.style.top=(event.clientY-deltaY)+"px";
            }
        }
    }    
    //实现层的拖动
    function katoon(currentObj,direction){ //当前对象,方向
        var step=5;
        var step1=5;
        var curTop;
        var aStep=0;
        var startTop;
        var startLeft;
        var Interval=null;
        var curaStep=100;
        var curObj=document.getElementById(currentObj);
        startTop=parseInt(curObj.style.top);
        startLeft=parseInt(curObj.style.left);
        if(direction.toLowerCase()=="d") 
            Interval=window.setInterval(down,1);
        else 
            Interval=window.setInterval(up,1);
        
        function down(){  //自上而下消失
            aStep+=5;
            curTop=parseInt(curObj.style.top);
            curObj.style.top=curTop+step+"px";
            curObj.style.filter="alpha(opacity="+(100-aStep)+")";
            if(aStep==curaStep) reset();
        }

        function reset(){  //恢复到以前的状态
            window.clearInterval(Interval);
            aStep=0;
            curObj.style.display="none";
            curObj.style.top=startTop;
            curObj.style.left=startLeft;
            curObj.style.filter="alpha(opacity=90)";
        }
    }
    function set_background(){
        var change_obj=document.getElementById("change_background");
        change_obj.style.display="block";
        change_obj.style.left="260px";
        change_obj.style.top="150px";
    }

    function FillDataC(strName)
    {
        var ArrayName=strName.substring(0,strName.indexOf("<!"));
        var arrData=new Array();
        arrData= ArrayName.split(",");
        
        if(arrData.length>2)
            alert("该分类下还有子分类,不可进行转移!");
        else{
            document.getElementById("ShowCheckOption").innerHTML="&nbsp;&nbsp;&nbsp;转移:&nbsp;<font color='red'>["+arrData[0]+"]</font>";  
            set_background();
        }
    }
    </script>
    
    <script type="text/javascript">

    function LDataI(strName)
    {
        var ArrayName=strName.substring(0,strName.indexOf("<!"));
        if(ArrayName.length>0) {
             var arrData=new Array();
             arrData= ArrayName.split(",");
             if(arrData.length>1)
                alert("转移成功!");
             else
                alert("转移失败!");
             katoon('change_background','d')
        }
    }
    </script>
    
    <script type="text/javascript">
    function IsShow(){    
       var xxoo= document.getElementById("pnlIndustryType");
       if(xxoo.style.display=="inline")
            xxoo.style.display="none";
       else
            xxoo.style.display="inline";
            }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div class="itemtitle">
            <h3>
                操作提示</h3>
        </div>
        <div class="itemtitle_tect">
            <ul>
                <li>批量删除功能，会删除该分类已经所有下级分类。同时还会删除分类下所有数据，请谨慎操作！</li>
                <li>转移功能，只可以转移该分类下的所有信息，并不会转移该分类。 </li>
                <li>信息提示:<asp:Label ID="lblMessages" runat="server" Text="" ForeColor="Red"></asp:Label></li>
            </ul>
            
        </div>
        <div class="clr">
        </div>
        <div id="pnlIndustryType" style="display:none;" runat="server">
            <div class="itemtitle">
                <h3>
                    添加行业分类</h3>
            </div>
            <div class="itemtitle_tect">
                <p>
                    行业分类名称：
                    <asp:TextBox ID="txtType" runat="server"></asp:TextBox>
                    允许发布：<asp:RadioButtonList ID="radlToRelease" runat="server" RepeatDirection="Horizontal"
                        RepeatLayout="Flow">
                        <asp:ListItem Selected="True" Value="True" Text="是"></asp:ListItem>
                        <asp:ListItem Value="False" Text="否"></asp:ListItem>
                    </asp:RadioButtonList>
                    排序：<asp:TextBox ID="txtSequence" runat="server" Width="20" Text="0"></asp:TextBox>
                    <asp:Button ID="btnInsert" runat="server" OnClick="btnInsert_Click" Text="添加" />
                    <input id="Button2" onclick="IsShow()" value="取消" type="button" />
                </p>
            </div>
            <div class="clr">
            </div>
        </div>
        <div class="partition">
            <div class="Option">
                <asp:Label ID="Label5" runat="server"><strong>快捷操作</strong></asp:Label>
                <span>
                    <asp:LinkButton ID="Button1" runat="server" OnClick="ButJS_Click" Text="生成分类JS" /></span>
                <span>
                    <label id="btnSave" onclick="IsShow()" style="cursor: hand;" >添加分类</label></span>
            </div>
        </div>
        <div class="clr">
            <asp:Label ID="Label1" runat="server"></asp:Label></div>
        <div class="talbe_border">
            <asp:GridView ID="grdIndustryType" runat="server" AutoGenerateColumns="False" AllowPaging="False"
                OnRowDeleting="grdIndustryType_RowDeleting" OnRowDataBound="grdIndustryType_RowDataBound"
                GridLines="None" DataKeyNames="ID" CssClass="talbe_list" OnRowEditing="grdIndustryType_RowEditing"
                OnRowUpdating="grdIndustryType_RowUpdating" OnRowCancelingEdit="grdIndustryType_RowCancelingEdit">
                <Columns>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:CheckBox ID="CheckBox1" runat="server" />
                        </ItemTemplate>
                        <HeaderStyle CssClass="th20 tou" />
                        <ItemStyle CssClass="nolet" />
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="排序">
                        <ItemTemplate>
                            <asp:TextBox ID="txtSequence" runat="server" Text='<%# Eval("Sequence") %>' onblur="IsNum(this);"
                                CssClass="i_corp"></asp:TextBox>
                            <asp:Label ID="Lb_id" runat="server" Text='<%#Eval("ID")%>' Visible="false"></asp:Label>
                        </ItemTemplate>
                        <HeaderStyle CssClass="th30" />
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="行业类别">
                        <ItemTemplate>
                            <a href='IndustryManage.aspx?ParentID=<%# DataBinder.Eval(Container.DataItem,"ID") %>'>
                                <%# DataBinder.Eval(Container.DataItem,"Type") %>
                            </a>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="txtName" runat="server" Text='<%# Eval("Type") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <ItemStyle CssClass="left2" />
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="是否允许发布">
                        <ItemTemplate>
                            <asp:LinkButton ID="lbtnUpdateToRelease" runat="server" Text='<%# Eval("ToRelease").ToString()=="True" ? "允许":"不允许"%>'
                                CommandArgument='<%# Eval("ID") +"|"+ Eval("ToRelease") %>' OnCommand="lbtnUpdateToRelease_Command"></asp:LinkButton>
                        </ItemTemplate>
                        <ItemStyle CssClass="th80" />
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="操作选项" ShowHeader="False">
                        <EditItemTemplate>
                            <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update"
                                Text="更新"></asp:LinkButton>
                            <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
                                Text="取消"></asp:LinkButton>
                        </EditItemTemplate>
                        <HeaderStyle CssClass="th80" />
                        <ItemTemplate>
                            <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit"
                                Text="编辑"></asp:LinkButton>
                            |
                            <asp:LinkButton ID="lbtnDelete" Style="text-decoration: none" runat="server" Text="删除"
                                CommandName="delete">
                            </asp:LinkButton>
                            |
                            <a id="lbtnMove" href="#" style="text-decoration: none" onclick="ajaxHandle(<%# Eval("ID") %>,'0')">转移</a>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <HeaderStyle CssClass="header" />
            </asp:GridView>
            <div class="Paging">
                <p>
                    <uc1:PageNo ID="PageNo1" runat="server" />
                </p>
                <input id="CheckBox2" name="CheckBox2" onclick="SelectAll();" type="checkbox" />全选
                <asp:Button ID="btnDelete" runat="server" Font-Size="9pt" OnClick="btnDelete_Click"
                    Text="批量删除" CssClass="i_button" />
                <asp:LinkButton ID="LinkButton1" runat="server" Text="排序" OnClick="LinkButton1_Click" CssClass="i_button"></asp:LinkButton>
                <asp:Label ID="lblMessage" runat="server" Visible="false"></asp:Label>
            </div>
        </div>
        <div id="change_background" style="left: 350; top: 250; display: none; width: 400px;
            height: 240px" class="change_background" >  
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<li><font color="red">提示:双击下拉列表操作</font></li>
                &nbsp;&nbsp;&nbsp;<div id="ShowCheckOption"></div><br />
                &nbsp;&nbsp;&nbsp;<div id="divFirst" style="display:inline;">一级分类:<asp:DropDownList ID="ddlFirst" Width="200" runat="server"  OnChange="ajaxHandle(this,'1')">
                </asp:DropDownList></div><br /><br />
                &nbsp;&nbsp;&nbsp;<div id="divSecond" style="display:none">二级分类:<asp:DropDownList ID="ddlSecond" Width="200" runat="server" OnChange="ajaxHandle(this,'2')">
                </asp:DropDownList></div><br /><br />
                &nbsp;&nbsp;&nbsp;<div id="divThird" style="display:none">三级分类:<asp:DropDownList ID="ddlThird" Width="200" runat="server">
                </asp:DropDownList></div><br /><br />
                <div style="text-align:center">
                <input onclick="ajaxHandle('d','3')" class="i_button" type="button" value="转移" />&nbsp;&nbsp;&nbsp;
                <input onclick="katoon('change_background','d')" class="i_button" type="button" value="取消" />
                </div>
        </div>
    </form>

    <script type="text/javascript" src="../../js/Common.js"></script>

    <script type="text/javascript"> 
    if ($("btnInsert")){
        $("btnInsert").onclick=function (){
            if($("txtType").value.replace(/\s/g,'')==""){
                alert("行业名称不能为空!")
                $("txtType").focus()
                return false
            }
            if($("txtSequence").value.replace(/\s/g,'')==""){
                alert("请输入排序数字!")
                $("txtSequence").focus()
                return false 
            } else if (!isNumber($("txtSequence").value.replace(/\s/g,''))){
                alert("请输入数字!")
                $("txtSequence").focus()
                return false; 
            }else{
                return true 
            }
        }
    }
     function IsNum(obj){
		 var vlu=obj.value.replace(/\D/g,'');
		 if(obj.value!=vlu){
		    alert("输入的必须都为整数");
		    obj.focus();
		 }
		 return false;
	}
    </script>

</body>
</html>
